<?php

/**
 * This is the model class for table "people".
 *
 * The followings are the available columns in table 'people':
 * @property integer $id
 * @property string $name
 * @property string $nickname
 * @property string $preTitle
 * @property string $postTitle
 * @property string $gender
 * @property string $birthDate
 * @property string $birthPlace
 * @property string $nationality
 * @property string $religion
 * @property string $matrimony
 * @property integer $bornSquence
 * @property integer $siblingTotal
 * @property string $createAt
 * @property string $updatedAt
 * @property integer $createdBy
 * @property integer $updatedBy
 */
class People extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'people';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, nickname, preTitle, postTitle, gender, birthDate, birthPlace, nationality, religion, matrimony, bornSquence, siblingTotal, createAt, updatedAt, createdBy, updatedBy', 'required'),
			array('bornSquence, siblingTotal, createdBy, updatedBy', 'numerical', 'integerOnly'=>true),
			array('name, nickname, preTitle, postTitle, gender, birthPlace, nationality, religion, matrimony', 'length', 'max'=>100),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, name, nickname, preTitle, postTitle, gender, birthDate, birthPlace, nationality, religion, matrimony, bornSquence, siblingTotal, createAt, updatedAt, createdBy, updatedBy', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'nickname' => 'Nickname',
			'preTitle' => 'Pre Title',
			'postTitle' => 'Post Title',
			'gender' => 'Gender',
			'birthDate' => 'Birth Date',
			'birthPlace' => 'Birth Place',
			'nationality' => 'Nationality',
			'religion' => 'Religion',
			'matrimony' => 'Matrimony',
			'bornSquence' => 'Born Squence',
			'siblingTotal' => 'Sibling Total',
			'createAt' => 'Create At',
			'updatedAt' => 'Updated At',
			'createdBy' => 'Created By',
			'updatedBy' => 'Updated By',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('nickname',$this->nickname,true);
		$criteria->compare('preTitle',$this->preTitle,true);
		$criteria->compare('postTitle',$this->postTitle,true);
		$criteria->compare('gender',$this->gender,true);
		$criteria->compare('birthDate',$this->birthDate,true);
		$criteria->compare('birthPlace',$this->birthPlace,true);
		$criteria->compare('nationality',$this->nationality,true);
		$criteria->compare('religion',$this->religion,true);
		$criteria->compare('matrimony',$this->matrimony,true);
		$criteria->compare('bornSquence',$this->bornSquence);
		$criteria->compare('siblingTotal',$this->siblingTotal);
		$criteria->compare('createAt',$this->createAt,true);
		$criteria->compare('updatedAt',$this->updatedAt,true);
		$criteria->compare('createdBy',$this->createdBy);
		$criteria->compare('updatedBy',$this->updatedBy);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return People the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
